package com.dm.hdfxxt.productmanage.controller;

import com.dm.hdfxxt.productmanage.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "goProduct")
public class ProductController {
    private static final Logger logger = LoggerFactory.getLogger(ProductController.class);

    @Autowired
    private ProductService productService;

    /**
     * @Description 保存产品信息
     * @Author zhangxue
     * @Date 18:29 2018/9/29
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/saveProduct",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> saveProduct(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        ResultMap = productService.saveProduct(param);
        return ResultMap;
    }

    /**
     * @Description 编辑产品信息
     * @Author zhangxue
     * @Date 18:29 2018/9/29
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/editProduct",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> editProduct(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        ResultMap = productService.editProduct(param);
        return ResultMap;
    }

    /**
     * @Description 删除产品信息
     * @Author zhangxue
     * @Date 18:29 2018/9/29
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/delProduct",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> delProduct(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        ResultMap = productService.delProduct(param);
        return ResultMap;
    }

    /**
         * @Description  查询所有产品
         * @Author zhangxue
         * @Date 11:35 2018/10/30
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllProduct",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllJxs(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        List<Map<String,Object>> ResultList = productService.queryAllProduct(param);
        ResultMap.put("ResultList",ResultList );
        return ResultMap;
    }
}
